/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restauranteaplicacion.Modificaciones;

import restauranteaplicacion.Ingresos.*;
import Clases.Observador;
import CapaNegocios.CNOrdenEntrada;
import java.util.List;
import entidad.Ordenentrada;
import java.awt.Component;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import restauranteaplicacion.MDI;
import entidad.Ordenentrada;
import java.awt.event.KeyEvent;
import java.util.Date;

/**
 *
 * @author Victor
 */
public class ModificacionCompras extends javax.swing.JInternalFrame implements Observer{

    /**
     * Creates new form IngresoEmpleado
     */
    Observador obs;
    //DefaultTableModel modelo;
    @SuppressWarnings("empty-statement")
    public ModificacionCompras() {
        initComponents();
        obs=new Observador();
        obs.addObserver(this);
    }
    


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        ordenentrada1 = new entidad.Ordenentrada();
        ordenentradaLista = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList((new java.util.ArrayList ()));
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        Tabla = new javax.swing.JTable();
        txtFactura = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        btnAgregar = new javax.swing.JButton();
        btnModificar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        lbTotal = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jDateChooser = new com.toedter.calendar.JDateChooser();
        btnBuscarFecha = new javax.swing.JButton();
        btnBuscarNombre = new javax.swing.JButton();
        btnBuscarFactura = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jLabel23 = new javax.swing.JLabel();
        label = new javax.swing.JLabel();

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.activo}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("activo"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.fecha}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("fecha"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idOrdenEntrada}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("idOrdenEntrada"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.lotesCollection}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("lotesCollection"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.noFactura}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("noFactura"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.proveedoridProveedor}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("proveedoridProveedor"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.total}"), ordenentrada1, org.jdesktop.beansbinding.BeanProperty.create("total"));
        bindingGroup.addBinding(binding);

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setIconifiable(true);
        setTitle("Compras");
        setAutoscrolls(true);
        setMaximumSize(new java.awt.Dimension(984, 649));
        setMinimumSize(new java.awt.Dimension(984, 649));
        setPreferredSize(new java.awt.Dimension(984, 649));
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));

        jPanel1.setBackground(new java.awt.Color(54, 149, 240));
        jPanel1.setMaximumSize(new java.awt.Dimension(2000, 50));
        jPanel1.setMinimumSize(new java.awt.Dimension(246, 50));
        jPanel1.setPreferredSize(new java.awt.Dimension(1000, 50));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Compras");
        jPanel1.add(jLabel4);

        getContentPane().add(jPanel1);

        jPanel4.setPreferredSize(new java.awt.Dimension(988, 430));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(494, 500));

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ordenentradaLista, Tabla);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${proveedoridProveedor.nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${noFactura}"));
        columnBinding.setColumnName("No Factura");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${total}"));
        columnBinding.setColumnName("Total");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fecha}"));
        columnBinding.setColumnName("Fecha");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        Tabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(Tabla);

        jScrollPane2.setBounds(20, 160, 840, 290);
        jLayeredPane3.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtFactura.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtFactura.setNextFocusableComponent(btnBuscarFactura);
        txtFactura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtFacturaKeyReleased(evt);
            }
        });
        txtFactura.setBounds(140, 80, 280, 30);
        jLayeredPane3.add(txtFactura, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel20.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel20.setText("<html>Fecha de Ingreso</html>");
        jLabel20.setBounds(40, 110, 90, 40);
        jLayeredPane3.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/plus-3x.png"))); // NOI18N
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });
        btnAgregar.setBounds(570, 60, 50, 40);
        jLayeredPane3.add(btnAgregar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/pencil-3x.png"))); // NOI18N
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        btnModificar.setBounds(650, 60, 50, 40);
        jLayeredPane3.add(btnModificar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/x-3x.png"))); // NOI18N
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        btnEliminar.setBounds(720, 60, 50, 40);
        jLayeredPane3.add(btnEliminar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel19.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel19.setText("FILTRAR COMPRAS POR:");
        jLabel19.setBounds(20, 10, 169, 17);
        jLayeredPane3.add(jLabel19, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lbTotal.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        lbTotal.setText("0.00");
        lbTotal.setBounds(750, 500, 50, 20);
        jLayeredPane3.add(lbTotal, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtNombre.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtNombre.setNextFocusableComponent(btnBuscarNombre);
        txtNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombreActionPerformed(evt);
            }
        });
        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNombreKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });
        txtNombre.setBounds(140, 40, 280, 30);
        jLayeredPane3.add(txtNombre, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel22.setText("<html>No Factura</html>");
        jLabel22.setBounds(40, 70, 90, 40);
        jLayeredPane3.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jDateChooser.setNextFocusableComponent(btnBuscarFecha);
        jDateChooser.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jDateChooserKeyReleased(evt);
            }
        });
        jDateChooser.setBounds(140, 120, 280, 30);
        jLayeredPane3.add(jDateChooser, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnBuscarFecha.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/magnifying-glass-2x.png"))); // NOI18N
        btnBuscarFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarFechaActionPerformed(evt);
            }
        });
        btnBuscarFecha.setBounds(430, 120, 40, 30);
        jLayeredPane3.add(btnBuscarFecha, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnBuscarNombre.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/magnifying-glass-2x.png"))); // NOI18N
        btnBuscarNombre.setNextFocusableComponent(txtFactura);
        btnBuscarNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarNombreActionPerformed(evt);
            }
        });
        btnBuscarNombre.setBounds(430, 40, 40, 30);
        jLayeredPane3.add(btnBuscarNombre, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnBuscarFactura.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/magnifying-glass-2x.png"))); // NOI18N
        btnBuscarFactura.setNextFocusableComponent(jDateChooser);
        btnBuscarFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarFacturaActionPerformed(evt);
            }
        });
        btnBuscarFactura.setBounds(430, 80, 40, 30);
        jLayeredPane3.add(btnBuscarFactura, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnCancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/circle-x-3x.png"))); // NOI18N
        btnCancelar.setText("Salir");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setPreferredSize(new java.awt.Dimension(89, 53));
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        btnCancelar.setBounds(20, 470, 89, 53);
        jLayeredPane3.add(btnCancelar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel23.setText("<html>Nombre Proveedor </html>");
        jLabel23.setBounds(40, 30, 90, 40);
        jLayeredPane3.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        label.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        label.setText("Total");
        label.setBounds(750, 460, 60, 20);
        jLayeredPane3.add(label, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 902, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 968, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 569, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel4);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

  
    
    private void CargarTabla(List<Ordenentrada> listatemp){
        ordenentradaLista.clear();
        agregarLista(ordenentradaLista,listatemp);
    }
    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        int fila =0;
        if(Tabla.getSelectedRow()>=0)
        {
            fila = JOptionPane.showInternalConfirmDialog(this, "Desea Eliminar "
                + " la orden", "Confirmacion",1, 0);
            if(fila == JOptionPane.OK_OPTION)
            {
                //eliminar el producto
                if(CNOrdenEntrada.eliminar(ordenentrada1))
                {
                    ordenentradaLista.remove(ordenentrada1);
                    JOptionPane.showMessageDialog(this, "Se elimino Correctamente", 
                        "Informacion", JOptionPane.INFORMATION_MESSAGE);
                }
                else
                    JOptionPane.showMessageDialog(this, "No se ha podido Eliminar", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else
            JOptionPane.showMessageDialog(this, "Debe de Seleccionar un elemento", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_btnEliminarActionPerformed

  
    
    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        //TODO add your handling code here:  
       if(Tabla.getSelectedRow()>= 0)
       {
           IngresoCompras ing = new IngresoCompras(obs, ordenentrada1);
           MDI.getDesktopPane().add(ing);
           ing.show();
           obs.addObserver(ing);
           Desactivar();
           
       }
        
    }//GEN-LAST:event_btnModificarActionPerformed

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        // TODO add your handling code here:
        IngresoCompras ing = new IngresoCompras(obs);
        MDI.getDesktopPane().add(ing);
        ing.show();
        obs.addObserver(ing);
        Desactivar();
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void TablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaMouseClicked
        // TODO add your handling code here:
        //int fila = Tabla.rowAtPoint(evt.getPoint());
        //proveedores1 =proveedorList.get(fila);
    }//GEN-LAST:event_TablaMouseClicked

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombreKeyTyped

    private void btnBuscarFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarFechaActionPerformed
        // TODO add your handling code here:
        buscarDatos();
    }//GEN-LAST:event_btnBuscarFechaActionPerformed

    private void btnBuscarNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarNombreActionPerformed
        // TODO add your handling code here:
        buscarDatos();
    }//GEN-LAST:event_btnBuscarNombreActionPerformed

    private void btnBuscarFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarFacturaActionPerformed
        // TODO add your handling code here:
        buscarDatos();
    }//GEN-LAST:event_btnBuscarFacturaActionPerformed

    private void txtFacturaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFacturaKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER)
            buscarDatos();
    }//GEN-LAST:event_txtFacturaKeyReleased

    private void jDateChooserKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jDateChooserKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER)
            buscarDatos();
    }//GEN-LAST:event_jDateChooserKeyReleased

    private void txtNombreKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER)
            buscarDatos();
    }//GEN-LAST:event_txtNombreKeyReleased

    private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombreActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombreActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed

        this.setVisible(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    public void buscarDatos()
    {
        boolean a=false,b=false,c=false;
        if(!txtNombre.getText().equals(""))
            a=true;
        if(!txtFactura.getText().equals(""))
            b=true;
        if(jDateChooser.getDate()!=null)
            c=true;
        if(a&&b&&c){
            CargarTabla(CNOrdenEntrada.buscarNombreFechaFactura(txtNombre.getText(),jDateChooser.getDate(),txtFactura.getText()));
            return;
        }
        if(a&&b){
            CargarTabla(CNOrdenEntrada.buscarNombreFactura(txtNombre.getText(),txtFactura.getText()));
            return;
        }
        else if(a&&c){
            CargarTabla(CNOrdenEntrada.buscarNombreFecha(txtNombre.getText(),jDateChooser.getDate())); 
            return;
        }
        else if (c&&b){
            CargarTabla(CNOrdenEntrada.buscarFacturaFecha(txtFactura.getText(),jDateChooser.getDate()));
            return;
        }        
        if(a)
            CargarTabla(CNOrdenEntrada.buscarNombre(txtNombre.getText())); 
        if(b)
            CargarTabla(CNOrdenEntrada.buscarFactura(txtFactura.getText()));
        if(c)
            CargarTabla(CNOrdenEntrada.buscarFecha(jDateChooser.getDate()));
        float p=0;
        if(ordenentradaLista!=null)
        {            
            for(Ordenentrada te : ordenentradaLista)//Ciclo para realizar la Sumatorias
            {
                    p=p+ te.getTotal();
            }            
        }
        lbTotal.setText(String.valueOf(p));
        
    }
    
    public void agregarLista(List lista, List nuevaLista)
    {
       if(nuevaLista!= null)
        {
            Iterator<?> ite = nuevaLista.iterator();
            while(ite.hasNext())
                lista.add(ite.next());
        }
        
    }
    
    private void Desactivar()
    {
        for(Component x :this.jPanel2.getComponents())
            x.setEnabled(false);
        Tabla.setEnabled(false);
        for(Component x : this.jLayeredPane3.getComponents())
            x.setEnabled(false);
    }
    private void Activar()
    {
        for(Component x :this.jPanel2.getComponents())
            x.setEnabled(true);
        Tabla.setEnabled(true);
        for(Component x : this.jLayeredPane3.getComponents())
            x.setEnabled(true);
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Tabla;
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnBuscarFactura;
    private javax.swing.JButton btnBuscarFecha;
    private javax.swing.JButton btnBuscarNombre;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnModificar;
    private com.toedter.calendar.JDateChooser jDateChooser;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel label;
    private javax.swing.JLabel lbTotal;
    private entidad.Ordenentrada ordenentrada1;
    private java.util.List<entidad.Ordenentrada> ordenentradaLista;
    private javax.swing.JTextField txtFactura;
    private javax.swing.JTextField txtNombre;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
       Activar();
       CargarTabla(CNOrdenEntrada.buscarNombre(txtNombre.getText()));
       
    }
}
